import Vue from 'vue'
import VueRouter from 'vue-router'
import {RouterTabRoutes} from 'vue-router-tab'

Vue.use(VueRouter)

//匹配路由名字获得对应组件
export const ruleMapping = {
    'menu': () => import("@/views/system/Menu"),
    'user': () => import("@/views/system/User"),
    'job': () => import("@/views/system/Job"),
    'role':() => import("@/views/system/Role"),
    'dept':() => import("@/views/system/Dept"),
    'loginlog':()=>import("@/views/monitor/LoginLog"),
    'operlog':()=>import("@/views/monitor/OperLog"),
}

//export const ruleMapping = {
//    menu: {
//        "menu": () => import("@/views/system/Menu"),
//        meta:{
//            title: "菜单管理"
//        }
//    },
//    user: {
//        "user":() => import("@/views/system/User"),
//        meta:{
//            title: "用户管理"
//        }
//    },
//    job: {
//        "job":() => import("@/views/system/Job"),
//        meta:{
//            title:"岗位管理"
//        }
//    },
//    role: {
//        "role":() => import("@/views/system/Role"),
//        meta:{
//            title:"角色管理"
//        }
//    },
//    dept: {
//        "dept":() => import("@/views/system/Dept"),
//        meta:{
//            title:"部门管理"
//        }
//    },
//}

//已存静态路由
const routes = [
    {
        path: '/',
        redirect: "/home"
    },
    {
        path: '/login',
        component: () => import("@/components/Login"),
    }
]

//动态路由的头部
export const authRoutes = {
    path: '/home',
    component: () => import("@/components/Home"),
    children: [
        ...RouterTabRoutes,
        {
            path: '/',
            redirect: "/index",
        },
        {
            path: '/index',
            component: () => import("@/components/Index"),
            meta: {
                title: '首页', // 页签标题
                //keepAlive: false
            }
        },]
}

//创建路由的方法
const createRouter = () => new VueRouter({
    mode: 'hash',
    routes: routes
})

//重置路由信息
export const resetRouter = () => {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
};

const router = createRouter()

export default router

//router.beforeEach((to, from, next) => {
//    //let item = sessionStorage.getItem("router");
//    if (to.path=== '/login') {
//        next()
//    } else {
//        //如果路由规则小于3条，那么就说明当前已经刷新了，因为定义的静态路由就2个
//        if (router.options.routes.length < 3) {
//
//        }
//        next('/login');
//    }
//
//    console.log(to.path)
//    console.log()
//    next()
//});